package com.landian.commons.base.utils;

import org.apache.commons.io.IOUtils;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

/**
 *
 * @author caojl
 * @create 2018/02/24
 **/
public class IOUtilsProxy {

    public static int copy(final InputStream input, final OutputStream output) throws IOException {
        try {
            return IOUtils.copy(input,output);
        } catch (IOException e) {
            closeStream(input, output);
            throw e;
        }
    }

    private static void closeStream(InputStream inputStream, OutputStream outputStream) throws IOException{
        try {
            if(null != inputStream){
                inputStream.close();
            }
        }catch (IOException ee) {
            throw ee;
        }
        try {
            if(null != outputStream){
                outputStream.close();
            }
        }catch (IOException ee) {
            throw ee;
        }
    }

}
